package nc.bs.wsdl.pub;

import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;

import com.alibaba.fastjson.JSONObject;

import nc.bs.framework.common.NCLocator;
import nc.bs.framework.common.RuntimeEnv;
import nc.bs.logging.Logger;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.wsdl.pub.IDataType;
import nc.itf.wsdl.pub.IParameter;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.vo.arap.basebill.BaseBillVO;
import nc.vo.arap.basebill.BaseItemVO;
import nc.vo.arap.gathering.GatheringBillItemVO;
import nc.vo.arap.pay.PayBillItemVO;
import nc.vo.arap.payable.PayableBillItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.lang.UFLiteralDate;
import nc.vo.pubapp.AppContext;

/**
 * 数据信息帮助类
 *
 * @author jieely
 * @date 2022-6-30
 *
 */
public class DataInfoHelper implements IParameter, IDataType
{
	private static IUAPQueryBS iQueryBS = null;

	private static IUAPQueryBS getUAPQueryBS()
	{
		if (iQueryBS == null)
		{
			iQueryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		}
		return iQueryBS;
	}

	/**
	 * 取服务器日期
	 *
	 * @return
	 */
	public static UFLiteralDate getServerDate()
	{
		UFDate serverUFDate = AppContext.getInstance().getServerTime().getDate();
		UFLiteralDate serverDate = new UFLiteralDate(serverUFDate.toDate());

		return serverDate;
	}

	/**
	 * 取服务器时间
	 *
	 * @return
	 */
	public static UFDateTime getServerTime()
	{
		return AppContext.getInstance().getServerTime();
	}

	/**
	 * 得到OA配置文件信息
	 *
	 * @return
	 */
	public static Properties getPropertyOA()
	{
		try
		{
			Properties properties = new Properties();
			String filePath = RuntimeEnv.getInstance().getNCHome() + IParameter.PropertiesPath_OA;
			FileInputStream file = new FileInputStream(filePath);
			properties.load(file);
			return properties;
		}
		catch (Exception e)
		{
			Logger.error("WSDLHRError:读取配置文件出错OAParameter");
		}
		return null;
	}

	/**
	 * 是否为空
	 *
	 * @param value
	 * @return
	 */
	public static boolean isEmpty(Object value)
	{
		if (value == null)
		{
			return true;
		}

		if (value.toString().trim().equals(""))
		{
			return true;
		}

		return false;
	}

	/**
	 * 格式化字符串
	 *
	 * @param tempinner
	 * @return
	 */
	public static String formatString(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		String tempouter = tempinner.toString();
		return tempouter;
	}

	/**
	 * 格式化短日期
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFLiteralDate formatUFLiteralDate(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFLiteralDate tempouter = new UFLiteralDate(tempinner.toString());
		return tempouter;
	}

	/**
	 * 格式化日期
	 *
	 * @param tempinner
	 * @return
	 * @throws BusinessException
	 * @throws Exception
	 */
	public static UFDate formatUFDate(Object tempinner) throws BusinessException
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFDate tempouter = null;
		try
		{
			if (tempinner.toString().length() == 10)
			{
				tempinner = tempinner.toString() + " 00:00:00";
			}
			tempouter = new UFDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(tempinner.toString()));
		}
		catch (Exception e)
		{
			throw new BusinessException("WSDLError:日期格式转换错误" + tempinner);
		}
		return tempouter;
	}

	/**
	 * 格式化日期-开始日期
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDate formatUFDateASBegin(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFDate tempouter = new UFDate(tempinner.toString()).asBegin();
		return tempouter;
	}

	/**
	 * 格式化日期-结束日期
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDate formatUFDateASEnd(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFDate tempouter = new UFDate(tempinner.toString()).asEnd();
		return tempouter;
	}

	/**
	 * 格式化整数
	 *
	 * @param tempinner
	 * @return
	 */
	public static Integer formatInteger(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		Integer tempouter = Integer.parseInt(tempinner.toString());
		return tempouter;
	}

	/**
	 * 格式化小数
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDouble formatUFDouble(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFDouble tempouter = new UFDouble(tempinner.toString());
		return tempouter;
	}

	/**
	 * 格式化2位小数
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDouble formatUFDouble2(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return UFDouble.ZERO_DBL;
		}

		UFDouble tempouter = new UFDouble(tempinner.toString(), 2);
		return tempouter;
	}

	/**
	 * 格式化3位小数
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDouble formatUFDouble3(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return UFDouble.ZERO_DBL;
		}

		UFDouble tempouter = new UFDouble(tempinner.toString(), 3);
		return tempouter;
	}

	/**
	 * 格式化4位小数
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFDouble formatUFDouble4(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return UFDouble.ZERO_DBL;
		}

		UFDouble tempouter = new UFDouble(tempinner.toString(), 4);
		return tempouter;
	}

	/**
	 * 格式化布尔型
	 *
	 * @param tempinner
	 * @return
	 */
	public static UFBoolean formatUFBoolean(Object tempinner)
	{
		if (tempinner == null || tempinner.equals(""))
		{
			return null;
		}

		UFBoolean tempouter = tempinner.equals("Y") ? UFBoolean.TRUE : UFBoolean.FALSE;
		return tempouter;
	}

	/**
	 * <单据主键>根据来源单据号查询
	 *
	 * @param tableName
	 * @param primaryKey
	 * @param srcKey
	 * @param srcValue
	 * @param wherePart
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getNCBillBySrcID(String tableName, String primaryKey, String srcKey, String srcValue, String wherePart) throws BusinessException
	{
		if (isEmpty(srcValue))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT " + primaryKey);
		sql.append("  FROM " + tableName);
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND " + srcKey + " = '" + srcValue + "' \n");
		sql.append(wherePart);

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			return null;
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的来源单据号【" + srcValue + "】,查询到多张NC单据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <集团主键>
	 *
	 * @return
	 * @throws BusinessException
	 */
	public static String getGroupPK() throws BusinessException
	{
		return Default_PKGroup;
	}

	/**
	 * <用户>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getUserPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT cuserid \n");// 用户主键
		sql.append("  FROM sm_user \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (user_code = '" + value + "' OR cuserid = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的用户【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的用户【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <交易类型>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getTradeTypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_billtypeid \n");// 主键
		sql.append("  FROM bd_billtype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND bd_billtype.pk_group <> 'global00000000000000' \n");// 非集团
		sql.append("   AND bd_billtype.istransaction = 'Y' \n");// 是否交易类型
		sql.append("   AND (pk_billtypecode = '" + value + "' OR pk_billtypeid = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的交易类型【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的交易类型【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <渠道类型>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getChanneltypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_type \n");// 主键
		sql.append("  FROM bd_channeltype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_type = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的渠道类型【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的渠道类型【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <供应商分类>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getSupplierClassPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_supplierclass \n");// 供应商分类主键
		sql.append("  FROM bd_supplierclass \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_supplierclass = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的供应商分类【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的供应商分类【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <供应商>根据关键字取信息
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, Object> getSupplierInfo(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_supplier, \n");// 供应商主键
		sql.append("	   code, \n");// 供应商编码
		sql.append("	   name, \n");// 供应商名称
		sql.append("	   supprop, \n");// 供应商类型
		sql.append("	   ts \n");
		sql.append("  FROM bd_supplier \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_supplier = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的供应商【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的供应商【" + value + "】,查询到多条数据");
		}

		String pk_supplier = (String) result.get(0)[0];// 供应商主键
		String code = (String) result.get(0)[1];// 供应商编码
		String name = (String) result.get(0)[2];// 供应商名称
		Integer supprop = (Integer) result.get(0)[3];// 供应商类型
		HashMap<String, Object> supplierMap = new HashMap<String, Object>();
		supplierMap.put("pk_supplier", pk_supplier);
		supplierMap.put("code", code);
		supplierMap.put("name", name);
		supplierMap.put("supprop", supprop);
		return supplierMap;
	}

	/**
	 * <供应商>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getSupplierPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_supplier \n");// 供应商主键
		sql.append("  FROM bd_supplier \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_supplier = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的供应商【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的供应商【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <收支项目>根据关键字取主键
	 *
	 * @param value
	 * @param pk_org
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getInOutBusiclassPK(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT bd_inoutbusiclass.pk_inoutbusiclass \n");// 主键
		sql.append("  FROM bd_inoutbusiclass \n");
		sql.append("  JOIN bd_inoutuse ON bd_inoutuse.pk_inoutbusiclass = bd_inoutbusiclass.pk_inoutbusiclass \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_inoutbusiclass.dr,0) = 0 \n");
		sql.append("   AND bd_inoutbusiclass.enablestate = 2 \n");
		sql.append("   AND bd_inoutuse.pk_org = '" + pk_org + "' \n");
		sql.append("   AND (bd_inoutbusiclass.code = '" + value + "' OR bd_inoutbusiclass.pk_inoutbusiclass = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的收支项目【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的收支项目【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <结算方式>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBalatypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_balatype \n");// 主键
		sql.append("  FROM bd_balatype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_balatype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的结算方式【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的结算方式【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <票据类型>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getNotetype(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_notetype \n");// 主键
		sql.append("  FROM bd_notetype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_notetype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的票据类型【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的票据类型【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <现金账户>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getCashaccount(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_cashaccount \n");// 主键
		sql.append("  FROM bd_cashaccount \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_cashaccount = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的现金账户【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的现金账户【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <项目基本分类>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getProjectEpsPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_eps \n");// 项目基本分类主键
		sql.append("  FROM pm_eps \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (eps_code = '" + value + "' OR pk_eps = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的项目基本分类【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的项目基本分类【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <项目>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getProjectPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_project \n");// 主键
		sql.append("  FROM bd_project \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (project_code = '" + value + "' OR pk_project = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的项目【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的项目【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <收付款类型>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getRecPayTypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_recpaytype \n");// 主键
		sql.append("  FROM fi_recpaytype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_recpaytype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的收付款类型【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的收付款类型【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <人员>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getPsndocPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_psndoc \n");// 主键
		sql.append("  FROM bd_psndoc \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_psndoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的人员【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的人员【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <部门>根据关键字取主键
	 *
	 * @param value
	 * @param pk_org
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getDeptOrgPKs(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value) || isEmpty(pk_org))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_dept, \n");// 部门主键
		sql.append("       pk_vid \n");// 部门版本主键
		sql.append("  FROM org_dept \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND pk_org = '" + pk_org + "' \n");// 组织主键
		sql.append("   AND (code = '" + value + "' OR pk_dept = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的部门【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的部门【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <客户>根据关键字取信息
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, Object> getCustomerInfo(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_customer, \n");// 客户主键
		sql.append("	   code, \n");// 客户编码
		sql.append("	   name, \n");// 客户名称
		sql.append("	   custprop, \n");// 客户类型
		sql.append("	   ts \n");
		sql.append("  FROM bd_customer \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_customer = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的客户【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的客户【" + value + "】,查询到多条数据");
		}

		String pk_customer = (String) result.get(0)[0];// 客户主键
		String code = (String) result.get(0)[1];// 客户编码
		String name = (String) result.get(0)[2];// 客户名称
		Integer custprop = (Integer) result.get(0)[3];// 客户类型
		HashMap<String, Object> customerMap = new HashMap<String, Object>();
		customerMap.put("pk_customer", pk_customer);
		customerMap.put("code", code);
		customerMap.put("name", name);
		customerMap.put("custprop", custprop);
		return customerMap;
	}

	/**
	 * <客户>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getCustomerPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_customer \n");// 主键
		sql.append("  FROM bd_customer \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_customer = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的客户【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的客户【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <业务单元>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getOrgPKs(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_org, \n");// 业务单元主键
		sql.append("       pk_vid \n");// 业务单元版本主键
		sql.append("  FROM org_orgs \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND isbusinessunit = 'Y' \n");
		sql.append("   AND (code = '" + value + "' OR pk_org = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的业务单元【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的业务单元【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <采购组织>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getPurchaseOrgPKs(String value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_purchaseorg, \n");// 采购组织主键
		sql.append("       pk_vid \n");// 采购组织版本主键
		sql.append("  FROM org_purchaseorg \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_purchaseorg = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的采购组织【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的采购组织【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <销售组织>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getSalesOrgPKs(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_salesorg, \n");// 销售组织主键
		sql.append("       pk_vid \n");// 销售组织版本主键
		sql.append("  FROM org_salesorg \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_salesorg = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的销售组织【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的销售组织【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <财务组织>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getFinanceOrgPKs(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_financeorg, \n");// 财务组织主键
		sql.append("       pk_vid \n");// 财务组织版本主键
		sql.append("  FROM org_financeorg \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_financeorg = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的财务组织【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的财务组织【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <项目组织>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String[] getItemOrgPKs(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_itemorg, \n");// 项目组织主键
		sql.append("       pk_vid \n");// 项目组织版本主键
		sql.append("  FROM org_itemorg \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_itemorg = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的项目组织【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的项目组织【" + value + "】,查询到多条数据");
		}

		String[] pks = new String[] { (String) result.get(0)[0], (String) result.get(0)[1] };
		return pks;
	}

	/**
	 * <订单类型>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBillTypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_billtypeid \n");// 订单类型主键
		sql.append("  FROM bd_billtype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND pk_group <> '" + IParameter.Default_PKglobal + "' \n");
		sql.append("   AND (pk_billtypecode = '" + value + "' OR pk_billtypeid = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的订单类型【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的订单类型【" + value + "】,查询到多条数据");
		}
		String pk_billtypeid = (String) result.get(0)[0];// 订单类型主键
		return pk_billtypeid;
	}

	/**
	 * <资产类别>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getCategoryPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		/**
		 * 数据查询
		 */
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_category \n");// 资产类别主键
		sql.append("  FROM fa_category \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (cate_code = '" + value + "' OR pk_category = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的资产类别【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的资产类别【" + value + "】,查询到多条数据");
		}
		String pk_billtypeid = (String) result.get(0)[0];// 资产类别主键
		return pk_billtypeid;
	}

	/**
	 * <物料>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getMaterialPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_material \n");// 物料主键
		sql.append("  FROM bd_material \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_material = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的物料【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的物料【" + value + "】,查询到多条数据");
		}

		String pk_material = (String) result.get(0)[0];
		return pk_material;
	}

	/**
	 * <计量单位>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getMeasdocPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_measdoc \n");// 单位主键
		sql.append("  FROM bd_measdoc \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_measdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的计量单位【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的计量单位【" + value + "】,查询到多条数据");
		}

		String pk_measdoc = (String) result.get(0)[0];
		return pk_measdoc;
	}

	/**
	 * <税率税码>根据关键字取值
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static Object[] getTaxrateInfo(String value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT bd_taxcode.pk_taxcode, \n");// 税率主键
		sql.append("	   bd_taxrate.taxrate, \n");// 税率值
		sql.append("	   bd_taxcode.code \n");// 税码
		sql.append("  FROM bd_taxcode \n");
		sql.append("  JOIN bd_taxrate ON bd_taxrate.pk_taxcode = bd_taxcode.pk_taxcode \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_taxcode.dr,0) = 0 \n");
		sql.append("   AND bd_taxcode.enablestate = 2 \n");
		sql.append("   AND (bd_taxcode.code = '" + value + "' OR bd_taxcode.pk_taxcode = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的税码【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的税码【" + value + "】,查询到多条数据");
		}

		String pk_taxcode = (String) result.get(0)[0];
		UFDouble taxrate = formatUFDouble(result.get(0)[1]);
		String code = (String) result.get(0)[2];

		Object[] taxrateInfo = new Object[] { pk_taxcode, taxrate, code };
		return taxrateInfo;
	}

	/**
	 * <银行类别>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBanktypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_banktype \n");// 银行类别主键
		sql.append("  FROM bd_banktype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_banktype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的银行类别【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的银行类别【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <网银信息模板>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getNetbankinftpPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_netbankinftp \n");// 网银信息模板主键
		sql.append("  FROM bd_netbankinftp \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND isdefault = 'Y' \n");
		sql.append("   AND (code = '" + value + "' OR pk_banktype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的网银信息模板【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的网银信息模板【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <银行档案>根据关键字取信息
	 *
	 * @param pk_bankdoc
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, String> getBankdocInfo(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT code, \n");// 银行档案编码
		sql.append("	   name, \n");// 银行档案名称
		sql.append("	   pk_bankdoc, \n");// 银行档案名称
		sql.append("	   pk_banktype, \n");// 银行类别
		sql.append("	   pcombinenum, \n");// 人行联行号码
		sql.append("	   pcombinename \n");// 人行联行名称
		sql.append("  FROM bd_bankdoc \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND enablestate = 2 \n");
		sql.append("   AND (code = '" + value + "' OR pk_bankdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的银行档案【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的银行档案【" + value + "】,查询到多条数据");
		}

		String code = (String) result.get(0)[0];// 银行档案编码
		String name = (String) result.get(0)[1];// 银行档案名称
		String pk_bankdoc = (String) result.get(0)[2];// 银行档案主键
		String pk_banktype = (String) result.get(0)[3];// 银行类别
		String pcombinenum = (String) result.get(0)[4];// 人行联行号码
		String pcombinename = (String) result.get(0)[5];// 人行联行名称
		HashMap<String, String> bankdocMap = new HashMap<String, String>();
		bankdocMap.put("code", code);
		bankdocMap.put("name", name);
		bankdocMap.put("pk_bankdoc", pk_bankdoc);
		bankdocMap.put("pk_banktype", pk_banktype);
		bankdocMap.put("pcombinenum", pcombinenum);
		bankdocMap.put("pcombinename", pcombinename);
		return bankdocMap;
	}

	/**
	 * <银行档案>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBankdocPK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_bankdoc \n");// 银行档案主键
		sql.append("  FROM bd_bankdoc \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_bankdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的银行档案【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的银行档案【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * 生成银行档案编码
	 *
	 * @param pk_banktype
	 * @param banktypeCode
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBankdocCode(String pk_banktype, String banktypeCode) throws BusinessException
	{
		String bankdocCode = null;// 生成的银行档案编码
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT MAX(code) \n");
		sql.append("  FROM bd_bankdoc \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND pk_banktype = '" + pk_banktype + "' \n");// 银行类别

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.get(0)[0] == null)
		{
			return banktypeCode + "000001";// 初始值
		}

		String maxBankdocCode = (String) result.get(0)[0];// 人员编码当前最大值
		int maxcode = Integer.parseInt(maxBankdocCode.substring(2, maxBankdocCode.length())) + 1;// 最大号加1

		String temp = maxcode + "";
		if (temp.length() == 6)
		{
			bankdocCode = banktypeCode + maxcode;
		}
		else if (temp.length() == 5)
		{
			bankdocCode = banktypeCode + "0" + maxcode;
		}
		else if (temp.length() == 4)
		{
			bankdocCode = banktypeCode + "00" + maxcode;
		}
		else if (temp.length() == 3)
		{
			bankdocCode = banktypeCode + "000" + maxcode;
		}
		else if (temp.length() == 2)
		{
			bankdocCode = banktypeCode + "0000" + maxcode;
		}
		else if (temp.length() == 1)
		{
			bankdocCode = banktypeCode + "00000" + maxcode;
		}
		else
		{
			throw new BusinessException("银行档案编码已超出最大流水号,请重新设置");
		}

		return bankdocCode;
	}

	/**
	 * <客户银行账号>根据关键字取主键
	 *
	 * @param value
	 * @param pk_customer
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getCustomerBankaccbasPK(String value, String pk_customer) throws BusinessException
	{
		if (isEmpty(value) || isEmpty(pk_customer))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT bd_bankaccsub.pk_bankaccsub \n");// 银行账户子户主键
		sql.append("  FROM bd_bankaccbas \n");
		sql.append("  JOIN bd_bankaccsub ON bd_bankaccsub.pk_bankaccbas = bd_bankaccbas.pk_bankaccbas \n");
		sql.append("  JOIN bd_custbank ON bd_custbank.pk_bankaccbas = bd_bankaccsub.pk_bankaccbas \n");
		sql.append("  LEFT JOIN bd_customer ON bd_customer.pk_customer = bd_custbank.pk_cust \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_bankaccbas.dr,0) = 0 \n");
		sql.append("   AND bd_bankaccbas.enablestate = 2 \n");// 银行账号启用状态=已启用
		sql.append("   AND bd_bankaccbas.accnum = '" + value + "' \n");
		sql.append("   AND bd_customer.pk_customer = '" + pk_customer + "' \n");// 客户主键

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的客户银行账号【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的客户银行账号【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <供应商银行账号>根据关键字取主键
	 *
	 * @param value
	 * @param pk_supplier
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getSuppbankaccPK(String value, String pk_supplier) throws BusinessException
	{
		if (isEmpty(value) || isEmpty(pk_supplier))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT bd_bankaccsub.pk_bankaccsub \n");// 银行账户子户主键
		sql.append("  FROM bd_bankaccbas \n");
		sql.append("  JOIN bd_bankaccsub ON bd_bankaccsub.pk_bankaccbas = bd_bankaccbas.pk_bankaccbas \n");
		sql.append("  JOIN bd_custbank ON bd_custbank.pk_bankaccbas = bd_bankaccsub.pk_bankaccbas \n");
		sql.append("  LEFT JOIN bd_supplier ON bd_supplier.pk_supplier = bd_custbank.pk_cust  \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_bankaccbas.dr,0) = 0 \n");
		sql.append("   AND bd_bankaccbas.enablestate = 2 \n");// 银行账号启用状态=已启用
		sql.append("   AND bd_bankaccbas.accnum = '" + value + "' \n");
		sql.append("   AND bd_supplier.pk_supplier = '" + pk_supplier + "' \n");// 供应商主键

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的供应商银行账号【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的供应商银行账号【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * <内部单位银行账号>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBankaccsubPK(String value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT bd_bankaccsub.pk_bankaccsub \n");
		sql.append("  FROM bd_bankaccsub \n");
		sql.append("  JOIN bd_bankaccbas ON bd_bankaccbas.pk_bankaccbas = bd_bankaccsub.pk_bankaccbas \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_bankaccsub.dr, 0) = 0 \n");
		sql.append("   AND NVL(bd_bankaccbas.dr, 0) = 0 \n");
		sql.append("   AND bd_bankaccbas.enablestate = 2 \n");// 启用
		sql.append("   AND bd_bankaccbas.accclass = 2 \n");// 账户分类:0=个人,1=客户,2=公司,3=供应商
		sql.append("   AND bd_bankaccsub.code = '" + value + "' \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的付款银行账号【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的付款银行账号【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];// 主键
		return pk;
	}

	/**
	 * <内部单位银行账号>根据关键字和组织取主键
	 * 校验组织下的收款/付款银行账户
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getBankaccsubPK2(String value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT bd_bankaccsub.pk_bankaccsub \n");
		sql.append("  FROM bd_bankaccsub \n");
		sql.append("  JOIN bd_bankaccbas ON bd_bankaccbas.pk_bankaccbas = bd_bankaccsub.pk_bankaccbas \n");
		sql.append("  JOIN org_orgs ON org_orgs.pk_org = bd_bankaccbas.pk_org \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_bankaccsub.dr, 0) = 0 \n");
		sql.append("   AND NVL(bd_bankaccbas.dr, 0) = 0 \n");
		sql.append("   AND bd_bankaccbas.enablestate = 2 \n");// 启用
		sql.append("   AND bd_bankaccbas.accclass = 2 \n");// 账户分类:0=个人,1=客户,2=公司,3=供应商
		sql.append("   AND (org_orgs.pk_org = '" + pk_org + "' OR org_orgs.pk_org='" + Default_PKOrg + "') \n");
		sql.append("   AND bd_bankaccsub.code = '" + value + "' \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的付款银行账号【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的付款银行账号【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];// 主键
		return pk;
	}

	/**
	 * <币种>根据关键字取主键
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getCurrtypePK(Object value) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT pk_currtype \n");// 币种主键
		sql.append("  FROM bd_currtype \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(dr,0) = 0 \n");
		sql.append("   AND (code = '" + value + "' OR pk_currtype = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的币种【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的币种【" + value + "】,查询到多条数据");
		}

		String pk = (String) result.get(0)[0];
		return pk;
	}

	/**
	 * 自定义档案<代收代付康居>
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getDefDocKJWY001PK(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_defdoc \n");// 主键
		sql.append("  FROM bd_defdoc \n");
		sql.append("  JOIN bd_defdoclist ON bd_defdoclist.pk_defdoclist = bd_defdoc.pk_defdoclist \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_defdoc.dr,0) = 0 \n");
		sql.append("   AND bd_defdoc.pk_org = '" + pk_org + "' \n");// 业务单元
		sql.append("   AND bd_defdoclist.code = 'kjwy001' \n");// kjwy001-代收代付康居
		sql.append("   AND (bd_defdoc.code = '" + value + "' OR bd_defdoc.pk_defdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的<代收代付康居>【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的<代收代付康居>【" + value + "】,查询到多条数据");
		}

		String pk_defdoc = (String) result.get(0)[0];// 主键
		return pk_defdoc;
	}

	/**
	 * 自定义档案<逾期银行档案>
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getDefCFJC0003(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_defdoc \n");// 主键
		sql.append("  FROM bd_defdoc \n");
		sql.append("  JOIN bd_defdoclist ON bd_defdoclist.pk_defdoclist = bd_defdoc.pk_defdoclist \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_defdoc.dr,0) = 0 \n");
		sql.append("   AND bd_defdoc.pk_org = '" + pk_org + "' \n");// 业务单元
		sql.append("   AND bd_defdoclist.code = 'CFJC0003' \n");// CFJC0003-逾期银行档案
		sql.append("   AND (bd_defdoc.code = '" + value + "' OR bd_defdoc.pk_defdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的<逾期银行档案>【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的<逾期银行档案>【" + value + "】,查询到多条数据");
		}

		String pk_defdoc = (String) result.get(0)[0];// 主键
		return pk_defdoc;
	}

	/**
	 * 自定义档案<无产权租赁资产>
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getDefCFJC0004(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_defdoc \n");// 主键
		sql.append("  FROM bd_defdoc \n");
		sql.append("  JOIN bd_defdoclist ON bd_defdoclist.pk_defdoclist = bd_defdoc.pk_defdoclist \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_defdoc.dr,0) = 0 \n");
		sql.append("   AND bd_defdoc.pk_org = '" + pk_org + "' \n");// 业务单元
		sql.append("   AND bd_defdoclist.code = 'CFJC0004' \n");// CFJC0004-无产权租赁资产
		sql.append("   AND (bd_defdoc.code = '" + value + "' OR bd_defdoc.pk_defdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的<无产权租赁资产>【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的<无产权租赁资产>【" + value + "】,查询到多条数据");
		}

		String pk_defdoc = (String) result.get(0)[0];// 主键
		return pk_defdoc;
	}

	/**
	 * 自定义档案<有产权租赁资产>
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getDefCFJC0005(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_defdoc \n");// 主键
		sql.append("  FROM bd_defdoc \n");
		sql.append("  JOIN bd_defdoclist ON bd_defdoclist.pk_defdoclist = bd_defdoc.pk_defdoclist \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_defdoc.dr,0) = 0 \n");
		sql.append("   AND bd_defdoc.pk_org = '" + pk_org + "' \n");// 业务单元
		sql.append("   AND bd_defdoclist.code = 'CFJC0005' \n");// CFJC0005-有产权租赁资产
		sql.append("   AND (bd_defdoc.code = '" + value + "' OR bd_defdoc.pk_defdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的<有产权租赁资产>【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的<有产权租赁资产>【" + value + "】,查询到多条数据");
		}

		String pk_defdoc = (String) result.get(0)[0];// 主键
		return pk_defdoc;
	}

	/**
	 * 自定义档案<代收代付款项>
	 *
	 * @param value
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static String getDefCFJC0006(Object value, String pk_org) throws BusinessException
	{
		if (isEmpty(value))
		{
			return null;
		}

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT pk_defdoc \n");// 主键
		sql.append("  FROM bd_defdoc \n");
		sql.append("  JOIN bd_defdoclist ON bd_defdoclist.pk_defdoclist = bd_defdoc.pk_defdoclist \n");
		sql.append(" WHERE 1 = 1 \n");
		sql.append("   AND NVL(bd_defdoc.dr,0) = 0 \n");
		sql.append("   AND bd_defdoc.pk_org = '" + pk_org + "' \n");// 业务单元
		sql.append("   AND bd_defdoclist.code = 'CFJC0006' \n");// CFJC0006-代收代付款项
		sql.append("   AND (bd_defdoc.code = '" + value + "' OR bd_defdoc.pk_defdoc = '" + value + "') \n");

		ArrayList<Object[]> result = (ArrayList<Object[]>) getUAPQueryBS().executeQuery(sql.toString(), new ArrayListProcessor());
		if (result == null || result.size() == 0)
		{
			throw new BusinessException("错误的<代收代付款项>【" + value + "】,未查询到数据");
		}
		if (result.size() > 1)
		{
			throw new BusinessException("错误的<代收代付款项>【" + value + "】,查询到多条数据");
		}

		String pk_defdoc = (String) result.get(0)[0];// 主键
		return pk_defdoc;
	}

	/**
	 * 应收应付<表头自定义项>转换
	 *
	 * @param baseAggVO
	 * @param jsonObject
	 * @return
	 * @throws BusinessException
	 */
	public static BaseBillVO changeHeadDefInfo(BaseBillVO baseBillVO, JSONObject jsonObject) throws BusinessException
	{
		/**
		 * 数据转换
		 */
		// String srcid = (String) jsonObject.get("srcid");// 来源系统主键
		// baseBillVO.setDef1(srcid);// 来源系统主键

		return baseBillVO;
	}

	/**
	 * 应收应付<表体自定义项>转换
	 *
	 * @param baseItemVO
	 * @param jsonObject
	 * @return
	 * @throws BusinessException
	 */
	public static BaseItemVO changeBodyDefInfo(BaseItemVO baseItemVO, JSONObject jsonObject) throws BusinessException
	{
		/**
		 * 表体自定义项报文解析
		 */
		String pk_org = baseItemVO.getPk_org();// 组织
		String def1 = formatString(jsonObject.get("def1"));// 流程
		String def2 = getDefDocKJWY001PK(jsonObject.get("def2"), pk_org);// 代收代付康居
		String def3 = getCategoryPK(jsonObject.get("def3"));// 资产类别
		String def4 = formatString(jsonObject.get("def4"));// 发票类型
		String def5 = getDefCFJC0003(jsonObject.get("def5"), pk_org);//逾期银行档案
		String def6 = getDefCFJC0004(jsonObject.get("def6"), pk_org);//无产权租赁资产
		String def7 = getDefCFJC0005(jsonObject.get("def7"), pk_org);//有产权租赁资产
		String def8 = getDefCFJC0006(jsonObject.get("def8"), pk_org);//代收代付款项

		/**
		 * 预置字段
		 */
		String def11 = formatString(jsonObject.get("def11"));// 自定义项11
		String def12 = formatString(jsonObject.get("def12"));// 自定义项12
		String def13 = formatString(jsonObject.get("def13"));// 自定义项13
		String def14 = formatString(jsonObject.get("def14"));// 自定义项14
		String def15 = formatString(jsonObject.get("def15"));// 自定义项15
		String def16 = formatString(jsonObject.get("def16"));// 自定义项16
		String def17 = formatString(jsonObject.get("def17"));// 自定义项17
		String def18 = formatString(jsonObject.get("def18"));// 自定义项18
		String def19 = formatString(jsonObject.get("def19"));// 自定义项19
		String def20 = formatString(jsonObject.get("def20"));// 自定义项20


		/**
		 * 收款单||应付单||付款单 自定义1不能为空
		 */
		if (DataInfoHelper.isEmpty(def1))
		{
			if (baseItemVO instanceof PayableBillItemVO || baseItemVO instanceof GatheringBillItemVO || baseItemVO instanceof PayBillItemVO)
			{
				throw new BusinessException("WSDLError:【def1】流程不能为空");
			}
		}

		baseItemVO.setDef1(def1);// 流程
		baseItemVO.setDef2(def2);// 代收代付康居
		baseItemVO.setDef3(def3);// 资产类别
		baseItemVO.setDef4(def4);// 发票类型
		baseItemVO.setDef5(def5);// 逾期银行档案

		//		String pk_billtype = baseItemVO.getPk_billtype();
		//		if ("F0".equals(pk_billtype))//应收单
		//		{
		//			baseItemVO.setDef6(def6);// 无产权租赁资产
		//			baseItemVO.setDef7(def7);// 有产权租赁资产
		//		}
		baseItemVO.setDef6(def6);// 无产权租赁资产
		baseItemVO.setDef7(def7);// 有产权租赁资产
		baseItemVO.setDef8(def8);// 代收代付款项

		baseItemVO.setDef11(def11);// 自定义项11
		baseItemVO.setDef12(def12);// 自定义项12
		baseItemVO.setDef13(def13);// 自定义项13
		baseItemVO.setDef14(def14);// 自定义项14
		baseItemVO.setDef15(def15);// 自定义项15
		baseItemVO.setDef16(def16);// 自定义项16
		baseItemVO.setDef17(def17);// 自定义项17
		baseItemVO.setDef18(def18);// 自定义项18
		baseItemVO.setDef19(def19);// 自定义项19
		baseItemVO.setDef20(def20);// 自定义项20

		return baseItemVO;
	}
}
